package cn.sm1234.controller;

import cn.sm1234.domain.User;
import org.springframework.scheduling.support.SimpleTriggerContext;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
public class UserController {

    // 展示列表
    @RequestMapping("/demo1")
    public String domo1(Model model){
        // 把数据存入模型model, 用作传递
        model.addAttribute("message", "hello, Thymeleaf");

        // 跳转到demo1.html, 放在templates下
        return "demo1";
    }

    // 变量输出
    @RequestMapping("/demo2")
    public String domo2(Model model){
        // 把数据存入模型model, 用作传递
        model.addAttribute("name", "Tom");

        // 跳转到demo1.html, 放在templates下
        return "demo2";
    }

    // 条件判断
    @RequestMapping("/demo3")
    public String domo3(Model model){
        // 把数据存入模型model, 用作传递
        model.addAttribute("gender", "female");
        model.addAttribute("grade", "2");

        // 跳转到demo3.html, 放在templates下
        return "demo3";
    }
    // 遍历
    @RequestMapping("/demo4")
    public String domo4(Model model){
        List<User> list = new ArrayList<User>();
        list.add(new User(1,2, "tom"));
        list.add(new User(2,21, "Jerry"));
        list.add(new User(3,22, "Jacky"));
        // 把数据存入模型model, 用作传递
        model.addAttribute("list", list);
        // 跳转到demo3.html, 放在templates下
        return "demo4";
    }

    // 域对象
    @RequestMapping("/demo5")
    public String domo5(HttpServletRequest req, Model model){
        // REQUEST
        req.setAttribute("request", "request's data");

        // session
        req.getSession().setAttribute("session", "session's data");

        // application
        req.getSession().getServletContext().setAttribute("application", "application's data");

        // 跳转到demo3.html, 放在templates下
        return "demo5";
    }

    // 超连接
    @RequestMapping("/demo6")
    public String domo6(HttpServletRequest req, Model model){
        return "demo6";
    }



}
